//
//  TheWaysMacro.h
//  DaFangYa
//
//  Created by lizhenqiang on 15/6/30.
//  Copyright (c) 2015年 HFKJ_LZQ. All rights reserved.
//

#ifndef DaFangYa_TheWaysMacro_h
#define DaFangYa_TheWaysMacro_h

#define UIColorFromRGB(r,g,b,a) [UIColor \
colorWithRed:r/255.0 \
green:g/255.0 \
blue:b/255.0 alpha:a]/*通过r、g、b、a来获取颜色*/
#define NSStringFromIntL(intValue) [NSString stringWithFormat:@"%ld",intValue]
#define NSStringFromInt(intValue) [NSString stringWithFormat:@"%d",intValue]/*整形转字符串*/
#define NSStringFromDouble(doubleValue) [NSString stringWithFormat:@"%f",doubleValue]/*double转字符串*/
#define NSStringFromDouble0(doubleValue) [NSString stringWithFormat:@"%.0f",doubleValue]/*double转0位小数字符串*/
#define NSStringIsEmpty(str) [NSString isEmpty:str]?@"":str
#define NSStringIsEmpty1(str) [NSString isEmpty:str]?@"暂无":str
#define DeviceRect   [UIScreen mainScreen].bounds
#define DeviceHeight [UIScreen mainScreen].bounds.size.height/*屏幕高度*/
#define DeviceWidth  [UIScreen mainScreen].bounds.size.width/*屏幕宽度*/

#define scaleWidth(width) (width*DeviceWidth/320.0) //效果图按640*1136来作
#define offSize ([UIScreen mainScreen].bounds.size.height- [UIScreen mainScreen].bounds.size.width)/2
#define KimageName(imageName) [UIImage imageNamed:imageName]
//#define kVersion     [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]/*获取app版本*/
//怎么适配 iPhone6 和 iPhone6plus
#define kplaceholderImage130  [UIImage imageNamed:@"moren130"]
#define kplaceholderImage224  [UIImage imageNamed:@"moren240"]
#define kplaceholderImageScroll  [UIImage imageNamed:@"moren1"]
#define kplaceholderImageCell  [UIImage imageNamed:@"moren"]
#define kplaceholderImage240  [UIImage imageNamed:@"moren240"]
#define kLoginDefaultBackImage  [UIImage imageNamed:@"loginBackGround"]

// 版本号
#define kVersion [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]
//#define myVersionBuild [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]

// 常用变量
#define kDefaultLastId [NSNumber numberWithInteger:99999999]

#define CDKeyWindow [UIApplication sharedApplication].keyWindow
#define SCREEN_W [UIScreen mainScreen].bounds.size.width /*屏幕宽度*/
#define SCREEN_H [[UIScreen mainScreen] bounds].size.height /*屏幕高度*/
#define SCREEN_Bounds [UIScreen mainScreen].bounds
#define kScaleFrom_iPhone5_Desgin(_X_) (_X_ * (SCREEN_W/320))
#define kScaleFrom_iphone6_Desgin(_X_) (_X_ * (SCREEN_W/375))

#define Is_iPhone4 (([[UIScreen mainScreen] bounds].size.height == 480) ? YES : NO)
#define Is_iPhone5 (([[UIScreen mainScreen] bounds].size.height == 568) ? YES : NO)
#define Is_iPhone6 (667 == [[UIScreen mainScreen] bounds].size.height ? YES : NO)
#define Is_iPhone6Plus (736 == [[UIScreen mainScreen] bounds].size.height ? YES : NO)


#define kPaddingLeftWidth 15.0
#define kLoginPaddingLeftWidth 18.0
#define kMySegmentControl_Height 44.0
#define kMySegmentControlIcon_Height 70.0

#define  kBackButtonFontSize 16.0
#define  kNavTitleFontSize 18.0
#define  kBadgeTipStr @"badgeTip"

#define kHigher_iOS_6_1 (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
#define kHigher_iOS_6_1_DIS(_X_) ([[NSNumber numberWithBool:kHigher_iOS_6_1] intValue] * _X_)
#define kNotHigher_iOS_6_1_DIS(_X_) (-([[NSNumber numberWithBool:kHigher_iOS_6_1] intValue]-1) * _X_)

// 常用公式
#define kPromptAlert(_S_, ...)     [[[UIAlertView alloc] initWithTitle:@"提示" message:[NSString stringWithFormat:(_S_), ##__VA_ARGS__] delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles:nil] show]

#define kUnReadKey_messages @"messages"
#define kUnReadKey_notifications @"notifications"
#define kUnReadKey_project_update_count @"project_update_count"
#define kUnReadKey_notification_AT @"notification_at"
#define kUnReadKey_notification_Comment @"notification_comment"
#define kUnReadKey_notification_System @"notification_system"

// 常用颜色
//#define kLinkAttributes     @{(__bridge NSString *)kCTUnderlineStyleAttributeName : [NSNumber numberWithBool:NO],(NSString *)kCTForegroundColorAttributeName : (__bridge id)[UIColor colorWithHexString:@"0x3bbd79"].CGColor}
//#define kLinkAttributesActive       @{(NSString *)kCTUnderlineStyleAttributeName : [NSNumber numberWithBool:NO],(NSString *)kCTForegroundColorAttributeName : (__bridge id)[[UIColor colorWithHexString:@"0x1b9d59"] CGColor]}



#define kColor999 [UIColor colorWithHexString:@"0x999999"]
#define kColorTableBG [UIColor colorWithHexString:@"0xfafafa"]
#define kColorTableSectionBg [UIColor colorWithHexString:@"0xeeeeee"]


#define kImage999 [UIImage imageWithColor:kColor999]

#define kPlaceholderMonkeyRoundWidth(_width_) [UIImage imageNamed:[NSString stringWithFormat:@"placeholder_monkey_round_%.0f", _width_]]
#define kPlaceholderMonkeyRoundView(_view_) [UIImage imageNamed:[NSString stringWithFormat:@"placeholder_monkey_round_%.0f", CGRectGetWidth(_view_.frame)]]

#define kPlaceholderCodingSquareWidth(_width_) [UIImage imageNamed:[NSString stringWithFormat:@"placeholder_coding_square_%.0f", _width_]]
#define kPlaceholderCodingSquareView(_view_) [UIImage imageNamed:[NSString stringWithFormat:@"placeholder_coding_square_%.0f", CGRectGetWidth(_view_.frame)]]


#define kTaskPrioritiesDisplay @[@"有空再看", @"正常处理", @"优先处理", @"十万火急"]


#define ESWeak(var, weakVar) __weak __typeof(&*var) weakVar = var
#define ESStrong_DoNotCheckNil(weakVar, _var) __typeof(&*weakVar) _var = weakVar
#define ESStrong(weakVar, _var) ESStrong_DoNotCheckNil(weakVar, _var); if (!_var) return;

#define ESWeak_(var) ESWeak(var, weak_##var);
#define ESStrong_(var) ESStrong(weak_##var, _##var);

/** defines a weak `self` named `__weakSelf` */
#define ESWeakSelf      ESWeak(self, __weakSelf);
/** defines a strong `self` named `_self` from `__weakSelf` */
#define ESStrongSelf    ESStrong(__weakSelf, _self);



#ifdef DEBUG_LOG

#  define CDLog(fmt, ...) do {                                            \
NSString* file = [[NSString alloc] initWithFormat:@"%s", __FILE__]; \
NSLog((@"%@(%d) " fmt), [file lastPathComponent], __LINE__, ##__VA_ARGS__); \
/*[file release];*/                                                 \
} while(0)

#  define LOG_METHOD NSLog(@"%s", __func__)
#  define LOG_CMETHOD NSLog(@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd))
#  define COUNT(p) NSLog(@"%s(%d): count = %d\n", __func__, __LINE__, [p retainCount]);
#  define LOG_TRACE(x) do {printf x; putchar('\n'); fflush(stdout);} while (0)
#else
#  define CDLog(...)
#  define LOG_METHOD
#  define LOG_CMETHOD
#  define COUNT(p)
#  define LOG_TRACE(x)
#endif

#endif
